#include <iostream>
#include <vector>
#include <functional>
#include <unistd.h>
#include <signal.h>
#include <string>
#include <stdlib.h>

using func_t = std::function<void()>;

int gcount = 0;
std::vector<func_t> gfuncs;

void handler(int signo)
{
	for(auto &f : gfuncs)
	{
		f();
	}
	std::cout << "gcount: " << gcount << std::endl;
	alarm(1);
}

int main()
{
	gfuncs.push_back([]()
					 { std::cout << "我是一个日志任务" << std::endl; });
	gfuncs.push_back([]()
					 { std::cout << "我是一个下载任务" << std::endl; });
	gfuncs.push_back([]()
					 { std::cout << "我是一个mysql任务" << std::endl; });

	alarm(1);// 一次性的闹钟
	signal(SIGALRM,handler);
	while (1)
	{
		pause();
		std::cout << "我醒来了..." << std::endl;
		gcount++;
	}

	return 0;
}